package com.poi.util;

import java.io.StringWriter;

import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.runtime.RuntimeConstants;
import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader;

import com.poi.entity.ExportRunnable;

public class TemplateUtil {
	
	
	
	public static String createTemplate(ExportRunnable task){
		VelocityEngine ve = new VelocityEngine();
		 ve.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
		 ve.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());
		 
		 ve.init();
		 Template t = ve.getTemplate("sqlTemp.vm");
		 VelocityContext ctx = new VelocityContext();
		 
		 
		 ctx.put("tableName",task.getTableName());
		 ctx.put("tableComment", task.getTableComment());
		 ctx.put("primaryKey", task.getPrimaryKey());
		 ctx.put("primaryKeyUp", task.getPrimaryKeyUp());
		 ctx.put("primaryKeyComment", "主键");
		 ctx.put("list", task.getTableEntity());
		 
		 StringWriter sw = new StringWriter();
		 
		 t.merge(ctx, sw);
		 
		 return sw.toString();
	}
	
	

}
